<template>
    <div>
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id == 0 ? 'mui-active': '']" v-for="item in navList" :key="item.id" @click="getPics(item.id)">{{item.name}}</a>
                </div>
            </div>
        </div>
        <div>
            <ul>
                <router-link v-for="item in pics" :key="item.objurl" tag="li" to="/home/picdetail">
                    <img v-lazy="item.objurl">
                    <p v-html="item.title"></p>
                </router-link>
            </ul>
        </div>
    </div>
</template>

<script>
import mui from '../../lib/mui/js/mui.min.js'
import { Toast } from "mint-ui";

export default {
    data () {
        return {
            navList: [],
            pics: []
        }
    },
    created() {
        this.getNav();
        this.getPics();
    },
    mounted() {
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005  // flick 减速系数，系数越大滚动速度越慢，滚动距离越小，默认值：0.0006
        });
    },
    methods: {
        getNav () {
            this.$http.get('getNav.json').then((result) => {
                result.body.unshift({ name: '全部', id: 0 });
                this.navList = result.body;
            },
            () => {
                Toast("请求数据失败！");
            });
        },
        getPics (id) {
            console.log('id:' + id || '0');
            this.$http.get('pics' + (id && id < 3 ? id-1 : '') + '.json').then((result) => {
                this.pics = result.body;
            },
            () => {
                Toast("请求数据失败！");
            });
        }
    }
}
</script>

<style scoped>
*{
    touch-action:pan-y;
}
image[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
ul li{
    text-align: center;
    margin-bottom:.1rem;
    box-shadow: 0 3px 3px rgba(0, 0, 0, .2);
    position:relative;
}
ul li img{
    width:100%;
    display: block;
}
ul li p{
    position:absolute;
    left:0;
    bottom:0;
    width:100%;
    background: rgba(0, 0, 0, .3);
    color:#fff;
    margin-bottom:0;
    text-align: left;
    max-height:2em;
    padding:.05rem .1rem;
    font-size:.14rem;
}
</style>

